package com.vr.caricature.local;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.vr.caricature.R;
import com.vr.caricature.common.VideoPageAdapter;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.InjectViews;
import butterknife.OnClick;

/**
 * Created by chengxiaozhi on 2016/11/6.
 */

public class LocalVideoFragment extends Fragment implements ViewPager.OnPageChangeListener{

    @InjectView(R.id.vp_local)ViewPager vpLocal;
    @InjectViews({R.id.tv_local,R.id.tv_wifi})List<TextView> tvTypes;

    private FragmentManager fm = null;
    private VideoPageAdapter fpAdapter = null;

    private int preCurrentPosition = 0;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view =  inflater.inflate(R.layout.fg_local,container,false);
        ButterKnife.inject(this,view);
        fm = getChildFragmentManager();
        fpAdapter = new VideoPageAdapter(fm,2);
        vpLocal.setAdapter(fpAdapter);
        vpLocal.setOnPageChangeListener(this);
        vpLocal.setCurrentItem(0);
        return view;
    }

    @OnClick(R.id.tv_local)
    public void local(){
        vpLocal.setCurrentItem(0);
    }

    @OnClick(R.id.tv_wifi)
    public void wifi(){
        vpLocal.setCurrentItem(1);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        tvTypes.get(position).setBackgroundResource(R.drawable.bg_fenlei_text);
        tvTypes.get(preCurrentPosition).setBackground(null);
        preCurrentPosition = position;
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

}
